package com.lmc.form.dao.dal.auto;



import com.free.bsf.core.util.ConvertUtils;
import com.free.bsf.core.db.DbConn;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.*;
import java.util.Date;
import com.lmc.form.dao.model.auto.*;

/**
 * paas_form_data 表自动dal映射,不要手工修改
 * 
 * @author 车江毅
 * @since 2022-04-30 22:27:34
 * 自动生成: https://gitee.com/makejava/EasyCode/wikis/
 */
public class paas_form_data_base_dal {

    public boolean add(DbConn conn, paas_form_data_model model) {
        val par = new Object[]{
            /**表单id*/
            model.form_id,
            /**父表单id*/
            model.parent_form_id,
            /**json数据,支持json索引和json数据查找*/
            model.json_data,
            /***/
            model.create_time,
            /***/
            model.update_time,
            /***/
            model.create_user,
            /***/
            model.update_user
        };
        int rev = conn.executeSql("insert into paas_form_data(form_id,parent_form_id,json_data,create_time,update_time,create_user,update_user)" +
                "values(?,?,?,?,?,?,?)", par);
        return rev == 1;
    }

    public boolean edit(DbConn conn, paas_form_data_model model) {
       val par = new Object[]{
           /**表单id*/
            model.form_id,
           /**父表单id*/
            model.parent_form_id,
           /**json数据,支持json索引和json数据查找*/
            model.json_data,
           /***/
            model.create_time,
           /***/
            model.update_time,
           /***/
            model.create_user,
           /***/
            model.update_user,
            model.id
        };
        int rev = conn.executeSql("update paas_form_data set form_id=?,parent_form_id=?,json_data=?,create_time=?,update_time=?,create_user=?,update_user=? where id=?", par);
        return rev == 1;

    }

    public boolean delete(DbConn conn, Integer id) {
        val par = new Object[]{id};
        String Sql = "delete from paas_form_data where id=?";
        int rev = conn.executeSql(Sql, par);
        if (rev == 1) {
            return true;
        } else {
            return false;
        }
    }

    public paas_form_data_model get(DbConn conn, Integer id) {
        val par = new Object[]{id};
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from paas_form_data s where s.id=?");
        val ds = conn.executeList(stringSql.toString(), par);
        if (ds != null && ds.size() > 0) {
            return createModel(ds.get(0));
        }
        return null;
    }

    public ArrayList<paas_form_data_model> list(DbConn conn) {
        val rs = new ArrayList<paas_form_data_model>();
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from paas_form_data s ");
        val ds = conn.executeList(stringSql.toString(), new Object[]{});
        if (ds != null && ds.size() > 0) {
            for (Map<String, Object> dr : ds) {
                rs.add(createModel(dr));
            }
        }
        return rs;
    }

    public paas_form_data_model createModel(Map<String, Object> dr) {
        val o = new paas_form_data_model();
        /***/
        if (dr.containsKey("id")) {
            o.id = ConvertUtils.convert(dr.get("id"),Integer.class);
        }
        /**表单id*/
        if (dr.containsKey("form_id")) {
            o.form_id = ConvertUtils.convert(dr.get("form_id"),Integer.class);
        }
        /**父表单id*/
        if (dr.containsKey("parent_form_id")) {
            o.parent_form_id = ConvertUtils.convert(dr.get("parent_form_id"),Integer.class);
        }
        /**json数据,支持json索引和json数据查找*/
        if (dr.containsKey("json_data")) {
            o.json_data = ConvertUtils.convert(dr.get("json_data"),String.class);
        }
        /***/
        if (dr.containsKey("create_time")) {
            o.create_time = ConvertUtils.convert(dr.get("create_time"),Date.class);
        }
        /***/
        if (dr.containsKey("update_time")) {
            o.update_time = ConvertUtils.convert(dr.get("update_time"),Date.class);
        }
        /***/
        if (dr.containsKey("create_user")) {
            o.create_user = ConvertUtils.convert(dr.get("create_user"),String.class);
        }
        /***/
        if (dr.containsKey("update_user")) {
            o.update_user = ConvertUtils.convert(dr.get("update_user"),String.class);
        }
        return o;
    }
}


